/* Story Mode Styles */
#story-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    overflow: hidden;
    z-index: 1000; /* Ensure it's above other screens when active */
    display: none; /* Hidden by default, toggled via JS */
}

#story-screen.active {
    display: block;
}

#story-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    transform: translate(-50%, -50%);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.5s ease-in-out;
    z-index: 1;
}

#story-cg-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    transition: opacity 0.5s ease-in-out;
    opacity: 0;
    z-index: 2;
}

#story-characters {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    transform: translate(-50%, -50%);
    z-index: 3;
    pointer-events: none; /* Let clicks pass through to advance text */
}

.story-character {
    position: absolute;
    bottom: -17.5%; /* For an 85% height char, adjust so ~50% is below the text box top */
    height: 85%; /* Adjust based on typical sprite size */
    width: 40%; /* Add width so background-size works */
    background-size: contain;
    background-position: bottom center;
    background-repeat: no-repeat;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    opacity: 0;
}

/* Character Positions */
.story-character.left { left: 5%; transform: translateX(0); }
.story-character.center { left: 50%; transform: translateX(-50%); }
.story-character.right { right: 5%; transform: translateX(0); }

.story-character.active {
    opacity: 1;
}

/* Dim inactive characters */
.story-character.inactive {
    opacity: 0.5;
    filter: brightness(0.7);
}

.story-top-buttons {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    display: flex;
    gap: 15px;
}

.story-btn {
    background: transparent;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 18px;
    cursor: pointer;
    transition: color 0.2s;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    font-weight: bold;
}

.story-btn:hover {
    color: #ffd700;
    background: transparent;
}

.story-btn.active {
    color: #ffd700;
    border-color: #ffd700;
}

.story-textbox-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30%;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.7) 60%, transparent 100%);
    z-index: 5;
    display: flex;
    align-items: flex-end;
    padding: 40px 10%;
    box-sizing: border-box;
    cursor: pointer; /* Indicate clickable to advance */
}

.story-name {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    width: 150px; /* Fixed width for name */
    flex-shrink: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    margin-bottom: 5px;
}

.story-text-wrapper {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.story-text {
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    min-height: 20px;
}

.story-text.en {
    font-size: 18px;
    color: #eee;
    line-height: 1.4;
}

.story-text.jp {
    font-size: 16px;
    color: #ccc;
    margin-top: 8px;
}

/* Hide UI elements when CG is full screen and text is hidden */
.story-ui-hidden .story-textbox-container,
.story-ui-hidden .story-top-buttons {
    opacity: 0;
    pointer-events: none;
}

/* Clash UI */
.clash-ui-container {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    background: rgba(0,0,0,0.85);
    border: 2px solid #555;
    border-radius: 8px;
    padding: 20px;
    display: none;
    justify-content: space-between;
    align-items: center;
    color: white;
    z-index: 1100;
    pointer-events: none;
}

.clash-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.side-label {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.2rem;
    color: #ffd700;
}

.dice-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.die {
    width: 36px;
    height: 36px;
    background: #222;
    border: 1px solid #666;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    font-weight: bold;
    color: #eee;
}

.die.broken {
    background: #400;
    color: #888;
    text-decoration: line-through;
    border-color: #600;
}

.clash-vs {
    font-size: 1.8rem;
    font-weight: bold;
    margin: 0 20px;
    color: #ff4444;
}

.side-total {
    margin-top: 10px;
    font-size: 1.4rem;
    font-weight: bold;
    color: #fff;
}

/* Story Choices */
.story-choices-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 60%;
    max-width: 400px;
    z-index: 1200;
}

.btn-choice {
    background: rgba(0,0,0,0.8);
    border: 2px solid #777;
    color: white;
    padding: 12px 20px;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    text-align: center;
}

.btn-choice:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: #ffd700;
    color: #ffd700;
}

/* Flash Effect */
.story-flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 1500; /* Top of everything in story screen */
}

.story-flash-overlay.red { background: rgba(180, 0, 0, 1); }
.story-flash-overlay.black { background: black; }
.story-flash-overlay.white { background: white; }

@keyframes story-flash-anim {
    0% { opacity: 0; }
    10% { opacity: 1; }
    100% { opacity: 0; }
}

.story-flash-overlay.do-flash {
    animation: story-flash-anim 0.5s ease-out forwards;
}

/* Slide Transitions */
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slide-in-right { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slide-in-up { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes slide-in-down { from { transform: translateY(100%); } to { transform: translateY(0); } }

@keyframes slide-out-left { from { transform: translateX(0); } to { transform: translateX(-100%); } }
@keyframes slide-out-right { from { transform: translateX(0); } to { transform: translateX(100%); } }

.slide-in-left { animation: slide-in-left 0.5s ease-out forwards; }
.slide-in-right { animation: slide-in-right 0.5s ease-out forwards; }
.slide-in-up { animation: slide-in-up 0.5s ease-out forwards; }
.slide-in-down { animation: slide-in-down 0.5s ease-out forwards; }

/* Zoom Support */
#story-scene-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease-out;
}

#story-bg, #story-cg-container {
    transition: background-image 0.5s ease-in-out, opacity 0.5s ease-in-out, transform 0.5s ease-out;
}
